﻿package net.sealuitk 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	/**
	 * ...
	 * @author mkn
	 */
	public class Util
	{	
		public static function getBitmapData(input:*):BitmapData {
			if (input is Bitmap) return input.bitmapData;
			if (input is BitmapData) return input;
			var e:String = new Error().getStackTrace();
			throw Error("Input must be Bitmap or BitmapData." + e);
		}
		
		public static function isBitmapSprite(obj:*):Boolean {
			if (obj is Sprite) return true;
			else if (obj is Bitmap) return true;
			else return false;
		}
		
		/**	Build a mask and return as Sprite
		 * 
		 * @param	xpos	Top left Position
		 * @param	ypos	Top left Position
		 * @param	xsize	Width of Mask
		 * @param	ysize	Height of Mask
		 * @return
		 */
		static public function buildMask(xpos:int, ypos:int, xsize:int, ysize:int):Sprite {
			var displayMask:Sprite = new Sprite();
			displayMask.graphics.beginFill(0xffffff, 1);
			displayMask.graphics.drawRect(xpos, ypos, xsize, ysize);
			displayMask.graphics.endFill();
			return displayMask;
		}
		
		static public function getClass(obj:Object):Class {
			return Class(getDefinitionByName(getQualifiedClassName(obj)));
		}
		
		static public function objectIsClass(obj:Object, cl:Class):Boolean {
			if (getClass(obj) is cl) return true;
			else return false;
		}
		
		static public function fixString(str:String):String {
			return str.toLowerCase();
		}
	}

}